import re
m = re.match(r'(\w+) (\w+)(?P<sign>.*)', 'hello world!')
print(m)
m = re.match('hello', 'hello world!')
print(m)
m = re.match('he\w{2}o', 'hello world!')
print(m)
m = re.match('^he\w{2}o$', 'hello world!')
print(m) #None
m = re.match('h\w{2}o', 'hello world!')
print(m) #None

m = re.match('^1\d{10}$', '12345678901')
print(m) 

# 将正则表达式编译成Pattern对象
pattern = re.compile(r'1\w3\w5',re.I | re.M)#I是忽略大小写，M是匹配多次
# 使用Pattern匹配文本，获得匹配结果，无法匹配时将返回None
match = pattern.findall('1a3b56781c3d5')
groups=match.groups()
if match:   
    print(match.group())
    print(match.groups())


str = "<span><h1>hello world!</h1></span><span><h1>helloWorld2!</h1></span>"
pattern = "<(?P<key1>.+)><(?P<key2>.+)>(?P<nr>\S*)<"
result = re.match(pattern, str,re.I | re.M)#I是忽略大小写，M是匹配多次
result.groups()

————————————————
版权声明：本文为CSDN博主「itw_wang」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
原文链接：https://blog.csdn.net/weixin_40136018/article/details/81183504




import re
ttt='"FileName":"陈雪凝 - <em>绿色<\/em>","FileName":"aa陈雪凝 - <em>绿色<\/em>","AlbumID":"15270740","ID":"130480126","SuperFileSize":0,"QualityLevel":3,"SQFileHash":"7B7A306B0000C77B85C300E80BCF3A2C","AlbumName":"绿色","HQPrivilege":10,"SuperBitrate":0,"SuperDuration":0,"MixSongID":"130480126","ResFileHash":"AD2FC906A25"'

res = re.findall('\"FileName\":\"([^\"]+)', ttt, re.I | re.M)#I是忽略大小写，M是匹配多次
print(res)
